<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>点击变色</title>
    <script src="../js/vue.js"></script>
    <style>
        .bg{
            background-color: #ff0000;
        }
        .bg2{
            background-color: grey;
        }
    </style>
</head>
<body>
    <div id="app">
        <ul>
            <li :class="{bg:num==index,bg2:count==index}" @click="change(index)" v-for="(item,index) in 10" :key="item">
                {{item}}
            </li>
        </ul>
    </div>
</body>
<script>
    let vm = new Vue({
        el:"#app",
        data:{
            num:11,
            count:11
        },
        methods:{
            change(index){
                if(index%2 == 0){
                    this.num = index
                    this.count = 11
                }else{
                    this.count = index
                    this.num = 11
                }
                
            }
        }
    })
</script>
</html>